package cn.aitrox.ry.app.web.controller.config;

import cn.aitrox.ry.app.web.vo.config.common.out.MaxCodeOutVo;
import cn.aitrox.ry.bean.CommonPageInfo;
import cn.aitrox.ry.bean.RespResult;
import cn.aitrox.ry.service.config.dto.ToolDto;
import cn.aitrox.ry.service.config.dto.in.ToolSearchInDto;
import cn.aitrox.ry.service.config.dto.in.ToolUpdateInDto;
import cn.aitrox.ry.service.config.feign.ToolFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ToolController {

    @Autowired
    @Lazy
    private ToolFeign toolFeign;


    @PostMapping(value = "/config/tool/search")
    public RespResult<CommonPageInfo<ToolDto>> toolSearch(@RequestBody ToolSearchInDto input) {
        CommonPageInfo<ToolDto> pageInfo = toolFeign.toolSearch(input);
        return  RespResult.ok(pageInfo);
    }

    @PutMapping(value = "/config/tool")
    public RespResult edit(@RequestBody ToolUpdateInDto input) {
        return toolFeign.edit(input);
    }

    @GetMapping(value = "/config/tool/maxCode")
    public RespResult<MaxCodeOutVo> maxCode() {
        String maxCode = toolFeign.maxCode();
        return RespResult.ok(new MaxCodeOutVo(maxCode));
    }
}
